package net.starwifi.duobao.job;

import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException;
import net.starwifi.duobao.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import net.starwifi.duobao.utils.times.DateTool;

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * 对账
 * Created by Administrator on 2015/7/27.
 */
@Component("balanceAccountJob")
@Lazy(false)
public class BalanceAccountJob {

    //合作方交易流水|合作方ID|付款方账户ID|收款方账户ID|服务号码|交易类型|交易金额|交易结果|交易时间
    @Autowired
    FileService fileService;

    @Autowired
    RefundsService refundsService;



    @Autowired
    private PluginService pluginService;
    @Autowired
    PaymentService paymentService;


//    /** 上传对账文件*/
//    @Scheduled(cron = "${job.paymentUpload.cron}")
//    public void push() {
//        try {
//            String path = "/home/www/file/";
//            String fileName = "P_AUDIT_DATA_" + getDate() + ".txt";
//            File file = new File(path + fileName);
//           // paymentService.exportTxtFile(file);
//            fileService.upload(file);
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (SftpException e) {
//            e.printStackTrace();
//        } catch (JSchException e) {
//            e.printStackTrace();
//        }
//    }


    private String getDate(){
        DateFormat format = new SimpleDateFormat("yyyyMMdd");
        Date date = DateTool.addDays(new Date(), -1);
        return  format.format(date);
    }

}
